package instructor.sample;
import java.sql.*;

public class OraDB
{
    public Connection conn;
    public Statement stmt;
    public OraDB()
    {
        conn = null;
        stmt = null;
    }
    public void createConnection()
        throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException
    {
        Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
        conn =  DriverManager.getConnection("jdbc:oracle:thin:@cigimlp01.corporate.ge.com:1521:orcl","BCAPURPLE","BCAPURPLE");
        stmt = conn.createStatement();
    }
    public void closeConnection()
        throws SQLException
    {
        conn.close();
        stmt.close();
    }
    public ResultSet Query(String s)
    {
        ResultSet rs = null;
        try
        {
          rs = stmt.executeQuery(s);
        }
        catch(SQLException sqlexception) {
			System.err.println("Exception! Query has failed **********");
			System.err.println(sqlexception);
      		System.err.println(s);
      	}

        return rs;
    }
    public synchronized int Update(String s)
    {
        int i = 0;
        try
        {
            i = stmt.executeUpdate(s);
        }
        catch(SQLException sqlexception) {
			System.err.println("Exception! Update has failed **********");
			System.err.println(sqlexception);
      		System.err.println(s);
			}
        return i;
    }
}
